<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: LJQ <liujiqi@etrol.com> 
// +----------------------------------------------------------------------

namespace app\service\controller;

use app\common\controller\Admin;
use app\service\controller\api\Law as LawApi;
use app\admin\controller\ajax\Library as Ajax;

/**
 * 法律法规管理
 * @package app\law
 */
class Law  extends Admin

{
    
    protected $api;
    
	public function _initialize()
	{
		parent::_initialize();
		$this->api = new LawApi();
            $this->ajax= new Ajax();
	}
    /**
     * 首页
     * 
     */
   	public function index() {
   	  if(IS_AJAX){
   	  	$lawList = $this->api->lawList();
   	  	return $lawList;
   	  }

 
      return $this->fetch();
 	}

 	/**
 	 * 搜索法律法规
 	 */
 	public function search($keyword) {
 		if(IS_AJAX){
			$lawList = $this->api->search(input('keyword'));
 			return $lawList;
 		}
 	}
    /**
     * 上传法律法规
     * 
     */
    public function add() {
   		 if(IS_POST){
   		 	$data = input('post.');  
   		 	//有效性
                   if(isset($data['isValid'])){
                     $data['isValid'] = 1;
                     }else{
                       $data['isValid'] = 0;
                     }
                    $data['operationId']=session('user_auth.id');
                    $getfile=$data['pathInfo'];
                    $data['end']=substr($getfile,strrpos($getfile,'.')+1);

                  return $this->api->add($data);
   		 }
           $type=$this->ajax->getDocumentLevelId()->getData();
         
           $this->assign('type',$type);
          
           return $this->fetch();    
     }
 
    /**
     * 修改法律法规
     * 
     */
    public function edit($lawId = null) {
      
    	  if(IS_POST){
    	  	$data = input('post.');
                  //有效性
                       if(isset($data['isValid'])){
                     $data['isValid'] = 1;
                     }else{
                       $data['isValid'] = 0;
                     }
                    $data['operationId']=session('user_auth.id');
                    if ($data['pathInfo']) {
                      $getfile=$data['pathInfo'];
                      $data['end']=substr($getfile,strrpos($getfile,'.')+1);
                    }
    	       	return $this->api->edit($data,$lawId);
    	  }
     	  $lawList = $this->api->lawList($lawId)->getData();
         $type=$this->ajax->getDocumentLevelId()->getData();
         $this->assign('type',$type);
     	  $this->assign('info',$lawList['data'][0]);
         return $this->fetch();      
    }
    
    /**
     * 删除法律法规
     */
    public function del($lawId = null) {
    	if(IS_AJAX){
    		return $this->api->del($lawId);
    	}
    }
  }



